import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '@/utils/storage'

Vue.use(Vuex)

// eslint-disable-next-line no-unused-vars
const TOUTIAO_TOUKEN = 'TOUTIAO_USER'

export default new Vuex.Store({
  state: {
    // user: JSON.parse(window.localStorage.getItem('TOUTIAO_TOUKEN'))
    user: getItem(TOUTIAO_TOUKEN)
  },
  mutations: {
    setuser (state, data) {
      state.user = data
      // 需要做本地持久化存储，避免刷新后丢失token
      // window.localStorage.setItem('TOUTIAO_TOUKEN', JSON.stringify(data))
      setItem(TOUTIAO_TOUKEN, state.user)
    }
  },
  actions: {},
  modules: {}
})
